package cn.fl.customer.controller;

import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import cn.cmm.base.framework.logger.eum.LogExceptionEnum;
import cn.cmm.base.framework.utils.*;
import cn.fl.customer.service.ICstBscInfoService;
import cn.fl.customer.transform.PrjBillBscInfoVOTransform;
import cn.fl.customer.utils.XmlUtils;
import cn.fl.customer.vo.*;
import cn.fl.project.dto.PrjBscInfoDTO;
import cn.fl.system.vo.SysUsrVO;
import com.alibaba.fastjson.JSON;
import fl.customer.facade.invoice.condition.SearchValidInvoiceQueryCondition;
import fl.customer.facade.invoice.constant.PrjBillApplyConstant;
import fl.customer.facade.invoice.dto.InvoiceApplyReqDTO;
import fl.customer.facade.invoice.dto.PrjBillFeeRDTO;
import fl.customer.facade.invoice.dto.ValidInvoiceDataDTO;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.alibaba.fastjson.JSONObject;

import cmm.mid.core.framework.dto.DataResultDTO;
import cmm.mid.core.framework.page.DataResultVO;
import cmm.mid.core.framework.page.KeyValueVO;
import cmm.mid.core.framework.page.ListPageVO;
import cmm.mid.core.framework.page.Pager;
import cmm.user.facade.system.condition.SysUsrQueryCondition;
import cmm.user.facade.system.dto.SysUsrDTO;
import cmm.web.core.framework.controller.BaseController;
import cn.cmm.base.framework.constant.BaseConstant;
import cn.cmm.base.framework.constant.BaseExceptionConstant;
import cn.cmm.base.framework.exception.BaseException;
import cn.cmm.cache.framework.utils.PropertiesCacheUtils;
import cn.fl.customer.service.IPrjBillApplyService;
import cn.fl.customer.service.IPrjBillFeeRService;
import cn.fl.framework.base.context.CurrentThreadContext;
import cn.fl.framework.constant.DictionaryConstant;
import cn.fl.system.constant.SysLogConstant;
import cn.fl.system.service.ISysDictionaryService;
import cn.fl.system.service.ISysUlFilesRecService;
import cn.fl.system.service.ISysUsrService;
import fl.constant.facade.framework.constant.TableConstant;
import fl.constant.facade.framework.constant.UploadConstant;
import fl.customer.facade.customer.constant.CustomerConstant;
import fl.customer.facade.invoice.condition.PrjBillApplyQueryCondition;
import fl.customer.facade.invoice.condition.PrjBillApplyRecQueryCondition;
import fl.customer.facade.invoice.condition.PrjBillFeeRQueryCondition;
import fl.flow.facade.flow.api.IFlowQueryApiService;
import fl.flow.facade.flow.condition.SysFlowSHQueryCondition;
import fl.flow.facade.flow.constant.FlowConstant;
import fl.flow.facade.flow.dto.FlowStartParamsDTO;
import fl.flow.facade.flow.dto.FlowStartedDTO;
import fl.flow.facade.flow.dto.SysFlowSHDTO;
import net.sf.json.JSONArray;

/**
 * @Description: 票据申请表表 控制层
 */
@Controller
@RequestMapping("/invoice/prjbillapply")
public class PrjBillApplyController extends BaseController {

	private static final Logger logger = LoggerFactory.getLogger(PrjBillApplyController.class);
	/**
	 * PrjBillFeeR 服务层BEAN
	 */
	@Autowired
	private IPrjBillFeeRService prjBillFeeRService;
	
	/**
	 * 服务层BEAN
	 */
	@Autowired
	private IPrjBillApplyService prjBillApplyService;
	
	@Autowired
	private ISysDictionaryService sysDictionaryService;
	@Autowired
	private ISysUsrService sysUsrService;
	@Autowired
	private IFlowQueryApiService flowQueryApiService;
	
	/**
	 * 附件服务
	 */
	@Autowired
	private ISysUlFilesRecService sysUlFilesRecService;

	@Autowired
    private ICstBscInfoService cstBscInfoService;

	/**
	 * 到发票申请新增页面
	 */
	@RequestMapping(value = "/toInvoiceApplyAddPage.do", method = { RequestMethod.GET })
	public ModelAndView toInvoiceApplyAddPage(HttpServletRequest request, HttpServletResponse response) {
		String cstId = request.getParameter("cstId");
		String cstNm = request.getParameter("cstNm");
		// 开票类型（1：纸质发票；2：电子发票）
		String flag = request.getParameter("flag");
		//支付表ID 和 项目ID是在特殊场景使用的,非正常开票使用
		String extPaySchMId = request.getParameter("extPaySchMId");
		String extPrjId = request.getParameter("extPrjId");
		ModelAndView view = new ModelAndView("customer/invoice/cstInvoiceApplyAdd");
		view.addObject("cstId", cstId);

		List<KeyValueVO> cntNosKV = this.prjBillApplyService.queryPrjByCstId(Long.valueOf(cstId));
		view.addObject("cntNosKV", JSON.toJSON(cntNosKV));


        List<KeyValueVO> feeTyps = this.prjBillApplyService.querySupportFeeTyp(PrjBillApplyConstant.BILL_WAY_CD_2);
        if (CollectionUtils.isNotEmpty(feeTyps)) {
            view.addObject("feeTyps", JSON.toJSON(feeTyps));
        }
        CstBscInfoVO cstBscInfoVO = this.cstBscInfoService.selectById(Long.valueOf(cstId));
        List<KeyValueVO> cstTypCd = this.sysDictionaryService.getKvList(DictionaryConstant.CODE_GRP_CST_TYP_CD, "11000", "0000");
        for (KeyValueVO keyValueVO : cstTypCd) {
            if (keyValueVO.getKey().equals(cstBscInfoVO.getCstTypCd())) {
                view.addObject("cstTypCd", keyValueVO.getKey());
                view.addObject("cstTypNm", keyValueVO.getValue());
            }
        }
        List<KeyValueVO> billStsCd = this.sysDictionaryService.getKvList(DictionaryConstant.CODE_PRJ_BILL_STS_CD, CurrentThreadContext.getFlServiceSysCd(), CurrentThreadContext.getCurrentOrgCd());
        view.addObject("billStsCd", JSON.toJSON(billStsCd));
		view.addObject("cstNm", cstNm);
		view.addObject("flag", flag);
		if(StringUtils.isEmpty(extPaySchMId)){
			extPaySchMId = "";
		}
		if(StringUtils.isEmpty(extPrjId)){
			extPrjId = "";
		}
		view.addObject("extPaySchMId", extPaySchMId);
		view.addObject("extPrjId", extPrjId);
		view.addObject("orgCd", CurrentThreadContext.getCurrentOrgCd());//当前组织架构
		view.addObject("orgCdNm", CurrentThreadContext.getCurrentOrgDispNm());//当前组织架构
		view.addObject("prjBillStsCdList", new JSONArray());
		try {
			List<String> codeGrpCdList = new ArrayList<>();
			codeGrpCdList.add(DictionaryConstant.CODE_PRJ_BILL_TYP_CD);
			codeGrpCdList.add(DictionaryConstant.CODE_SYS_YES_NO_CD);
			codeGrpCdList.add(DictionaryConstant.CODE_GRP_CST_NP_BK_CD);
			//加入一个发票类型
			Map<String, List<KeyValueVO>> map = this.sysDictionaryService.getMultiKvList(CurrentThreadContext.getFlServiceSysCd(), CurrentThreadContext.getCurrentOrgCd(), codeGrpCdList);
			view.addObject("prjBillStsCdList", com.alibaba.fastjson.JSONArray.toJSON(map.get(DictionaryConstant.CODE_PRJ_BILL_TYP_CD)));
			List<KeyValueVO> ynList = map.get(DictionaryConstant.CODE_SYS_YES_NO_CD);
			if(CollectionUtils.isEmpty(ynList)){
				ynList = new ArrayList<>();
			}
			view.addObject("ynList", ynList);
			//开户银行
			List<KeyValueVO> bkCdList =  map.get(DictionaryConstant.CODE_GRP_CST_NP_BK_CD);
			if(CollectionUtils.isEmpty(bkCdList)){
				bkCdList = new ArrayList<>();
			}
			view.addObject("selectBkCdList", bkCdList);
		} catch (Exception e) {
			BaseLogUtils.error(logger, "toListPage", "获取数据字典组数据失败." + e.getMessage(), CurrentThreadContext.getCurrentUserName());
		}
		
		BaseLogUtils.info(logger, "toInvoiceApplyAddPage", "跳转到发票申请新增页面", CurrentThreadContext.getCurrentUserName());
		return view;
	}
	
	/**
	 * 到列表页面
	 */
	@RequestMapping(value = "/toListPage.do", method = { RequestMethod.GET})
	public ModelAndView toListPage(HttpServletRequest request, HttpServletResponse response) {
		ModelAndView view = new ModelAndView("customer/invoice/cstInvoiceApplyList");
		BaseLogUtils.info(logger, "toListPage", "跳转到发票申请列表页面.", CurrentThreadContext.getCurrentUserName());
		return view;
	}
	
	/**
	 * 到财务管理列表页面
	 */
	@RequestMapping(value = "/toFinanceListPage.do", method = { RequestMethod.GET})
	public ModelAndView toSearchListPage(HttpServletRequest request, HttpServletResponse response) {
		ModelAndView view = new ModelAndView("customer/invoice/cstInvoiceFinanceList");
		BaseLogUtils.info(logger, "toListPage", "跳转到发票申请列表页面.", CurrentThreadContext.getCurrentUserName());
		return view;
	}

	/**
	 * 到修改页面
	 */
	@RequestMapping(value = "/toModifyPage.do", method = { RequestMethod.GET, RequestMethod.POST })
	public ModelAndView toModifyPage(HttpServletRequest request, HttpServletResponse response) {
		String id = request.getParameter("id");
		ModelAndView view = new ModelAndView("customer/invoice/cstInvoiceApplyModify");
		view.addObject("id", id);
		view.addObject("prjBillStsCdList", new JSONArray());
		try {
            List<KeyValueVO> feeTyps = this.prjBillApplyService.querySupportFeeTyp(PrjBillApplyConstant.BILL_WAY_CD_2);
            if (CollectionUtils.isNotEmpty(feeTyps)) {
                view.addObject("feeTyps", JSON.toJSON(feeTyps));
            }
			List<String> codeGrpCdList = new ArrayList<>();
			codeGrpCdList.add(DictionaryConstant.CODE_PRJ_BILL_TYP_CD);
			codeGrpCdList.add(DictionaryConstant.CODE_SYS_YES_NO_CD);
			codeGrpCdList.add(DictionaryConstant.CODE_GRP_CST_NP_BK_CD);
			//加入一个发票类型
			Map<String, List<KeyValueVO>> map = this.sysDictionaryService.getMultiKvList(CurrentThreadContext.getFlServiceSysCd(), CurrentThreadContext.getCurrentOrgCd(), codeGrpCdList);
			view.addObject("prjBillStsCdList", com.alibaba.fastjson.JSONArray.toJSON(map.get(DictionaryConstant.CODE_PRJ_BILL_TYP_CD)));
		
			List<KeyValueVO> ynList = map.get(DictionaryConstant.CODE_SYS_YES_NO_CD);
			if(CollectionUtils.isEmpty(ynList)){
				ynList = new ArrayList<>();
			}
			view.addObject("ynList", ynList);
			//开户银行
			List<KeyValueVO> bkCdList =  map.get(DictionaryConstant.CODE_GRP_CST_NP_BK_CD);
			if(CollectionUtils.isEmpty(bkCdList)){
				bkCdList = new ArrayList<>();
			}
			view.addObject("selectBkCdList", bkCdList);
		} catch (Exception e) {
			BaseLogUtils.error(logger, "toListPage", "获取数据字典组数据失败." + e.getMessage(), CurrentThreadContext.getCurrentUserName());
		}
		BaseLogUtils.info(logger, "toModifyPage", "跳转到修改页面.[id="+id+"]", CurrentThreadContext.getCurrentUserName());
		return view;
	}

	/**
	 * 初始化列表
	 */
	@SuppressWarnings("unchecked")
	@RequestMapping(value = "/initList.do", method = { RequestMethod.GET})
	@ResponseBody
	public Object initList(HttpServletRequest request, HttpServletResponse response) {
		String currentPage = request.getParameter("page");
		String pageSize = request.getParameter("pagesize");
		String applyTm = request.getParameter("applyTm");
		String cstMgrNm = request.getParameter("cstMgrNm");
		String rcverNm = request.getParameter("rcverNm");
		String cstNm = request.getParameter("cstNm");
		String paySchNo = request.getParameter("paySchNo");
		//非正常开票参数,这个参数是过滤支付表拥有的申请数据
		String extPaySchMId = request.getParameter("extPaySchMId");
		String rlFlowCd = request.getParameter("rlFlowCd");//这个是是否过滤指定来源流程数据
		
		Pager page = new Pager();
		if (StringUtils.isNotEmpty(currentPage)) {
			page.setCurrentPage(Integer.parseInt(currentPage));
		}

		if (StringUtils.isNotEmpty(pageSize)) {
			page.setEveryPage(Integer.parseInt(pageSize));
		}

		PrjBillApplyQueryCondition qc = new PrjBillApplyQueryCondition();
		if (StringUtils.isNotEmpty(applyTm)) {
			try {
				qc.setApplyTm(DateUtils.formatStringToDate(applyTm, DateUtils.YYYY_MM_DD));
			} catch (Exception e) {
				BaseLogUtils.info(logger, "initList", "格式化时间条件失败!");
			}
		}
		
		if (StringUtils.isNotEmpty(cstMgrNm)) {
			qc.setCstMgrNm(cstMgrNm);
		}

		if (StringUtils.isNotEmpty(rcverNm)) {
			qc.setRcverNm(rcverNm);
		}
		
		if (StringUtils.isNotEmpty(cstNm)) {
			qc.setCstNm(cstNm);
		}
		
		if(StringUtils.isNotEmpty(extPaySchMId)){
			qc.setPaySchMId(Long.valueOf(extPaySchMId));
		}
		
		if(StringUtils.isNotEmpty(rlFlowCd)){
			qc.setRlFlowCd(rlFlowCd);
		}
		if(StringUtils.isNotEmpty(paySchNo)){
			Long applyId = getApplyIdByPaySchNo(paySchNo);
			if(applyId != null && applyId > 0){
				qc.setApplyId(applyId);
			}
		}
		//是否需要权限
		qc.setisAuth(true);
		
		qc.setSysCd(CurrentThreadContext.getFlServiceSysCd());
		qc.setOrgCd(CurrentThreadContext.getCurrentOrgCd());
		qc.setUserId(CurrentThreadContext.getCurrentUserId());
		page.setCondition(qc);

		Pager pager = this.prjBillApplyService.searchListPage(page);
		List<PrjBillApplyVO> list = (List<PrjBillApplyVO>) pager.getResultList();
		ListPageVO<PrjBillApplyVO> listPage = new ListPageVO<PrjBillApplyVO>(list, pager.getTotalCount());
		BaseLogUtils.info(logger, "initList", "查询数据完成. DATA:" + JSONObject.toJSONString(page), CurrentThreadContext.getCurrentUserName());
		return listPage;
	}
	
	
	private Long getApplyIdByPaySchNo(String paySchNo) {
		PrjBillFeeRQueryCondition qc = new PrjBillFeeRQueryCondition();
		qc.setPaySchNo(paySchNo);
		qc.setOrgCd(CurrentThreadContext.getCurrentOrgCd());
		qc.setSysCd(CurrentThreadContext.getCurrentSysCd());
		List<PrjBillFeeRVO> list = this.prjBillFeeRService.searchList(qc);
		if(CollectionUtils.isNotEmpty(list)){
			return list.get(0).getApplyId();
		}
		return 0L;
	}

	/**
	 * 初始化列表(财务)
	 */
	@SuppressWarnings("unchecked")
	@RequestMapping(value = "/initFinanceList.do", method = { RequestMethod.GET})
	@ResponseBody
	public Object initFinanceList(HttpServletRequest request, HttpServletResponse response) {
		String currentPage = request.getParameter("page");
		String pageSize = request.getParameter("pagesize");
		String applyTm = request.getParameter("applyTm");
		String cstMgrNm = request.getParameter("cstMgrNm");
		String rcverNm = request.getParameter("rcverNm");
		String cstNm = request.getParameter("cstNm");
		String paySchNo = request.getParameter("paySchNo");
        String invoiceCode = request.getParameter("invoiceCode");
        String billNo = request.getParameter("billNo");
		Pager page = new Pager();
		if (StringUtils.isNotEmpty(currentPage)) {
			page.setCurrentPage(Integer.parseInt(currentPage));
		}

		if (StringUtils.isNotEmpty(pageSize)) {
			page.setEveryPage(Integer.parseInt(pageSize));
		}

		PrjBillApplyQueryCondition qc = new PrjBillApplyQueryCondition();
		if (StringUtils.isNotEmpty(applyTm)) {
			try {
				qc.setApplyTm(DateUtils.formatStringToDate(applyTm, DateUtils.YYYY_MM_DD));
			} catch (Exception e) {
				BaseLogUtils.info(logger, "initList", "格式化时间条件失败!");
			}
		}
		
		if (StringUtils.isNotEmpty(cstMgrNm)) {
			qc.setCstMgrNm(cstMgrNm);
		}

		if (StringUtils.isNotEmpty(rcverNm)) {
			qc.setRcverNm(rcverNm);
		}
		
		if (StringUtils.isNotEmpty(cstNm)) {
			qc.setCstNm(cstNm);
		}
		if(StringUtils.isNotEmpty(paySchNo)){
			//根据支付表号获取申请表ID
			Long applyId = getApplyIdByPaySchNo(paySchNo);
			if(applyId != null && applyId > 0){
				qc.setApplyId(applyId);
			}
			
		}
        if (StringUtils.isNotEmpty(invoiceCode)) {
            qc.setInvoiceCode(invoiceCode);
        }
        if (StringUtils.isNotEmpty(billNo)) {
            qc.setBillNo(billNo);
        }
		//是否需要权限
		qc.setisAuth(false);
        // 审核中和审核通过的数据都要查出来
        List<String> audStsCdList = new ArrayList<>(2);
        audStsCdList.add(FlowConstant.FLOW_CHECK_STATE_PASS);
        audStsCdList.add(FlowConstant.FLOW_CHECK_STATE_IN);
        qc.setAudStsCdList(audStsCdList);
		qc.setSysCd(CurrentThreadContext.getFlServiceSysCd());
		qc.setOrgCd(CurrentThreadContext.getCurrentOrgCd());
		qc.setUserId(CurrentThreadContext.getCurrentUserId());
		page.setCondition(qc);

		Pager pager = this.prjBillApplyService.searchListPage(page);
		List<PrjBillApplyVO> list = (List<PrjBillApplyVO>) pager.getResultList();
		ListPageVO<PrjBillApplyVO> listPage = new ListPageVO<PrjBillApplyVO>(list, pager.getTotalCount());
		BaseLogUtils.info(logger, "initList", "查询数据完成. DATA:" + JSONObject.toJSONString(page), CurrentThreadContext.getCurrentUserName());
		return listPage;
	}
	/**
	 * 初始化支付表申请列表
	 */
//	@RequestMapping(value = "/initApplyList.do", method = { RequestMethod.GET})
//	@ResponseBody
//	public Object initApplyList(HttpServletRequest request, HttpServletResponse response) {
//		String currentPage = request.getParameter("page");
//		String pageSize = request.getParameter("pagesize");
//		String cstId = request.getParameter("cstId");
//		String isPreInv = request.getParameter("isPreInv");//是否是提前结清
//		//支付表ID 和 项目ID是在特殊场景使用的,非正常开票使用
//		String extPaySchMId = request.getParameter("extPaySchMId");
//		String extPrjId = request.getParameter("extPrjId");
//		Pager page = new Pager();
//		if (StringUtils.isNotEmpty(currentPage)) {
//			page.setCurrentPage(Integer.parseInt(currentPage));
//		}
//
//		if (StringUtils.isNotEmpty(pageSize)) {
//			page.setEveryPage(Integer.parseInt(pageSize));
//		}
//
//		if(StringUtils.isEmpty(cstId)){
//			throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_600, "客户ID不能为空!");
//		}
//
//
//		PrjBillApplyRecQueryCondition qc = new PrjBillApplyRecQueryCondition();
//
//		//客户ID
//		qc.setCstId(Long.valueOf(cstId));
//		if(StringUtils.isEmpty(isPreInv)){
//			qc.setIsPreInv(BaseConstant.IS_YESNO_NO);
//		}else if(isPreInv.equals(String.valueOf(BaseConstant.IS_YESNO_YES))){
//			qc.setIsPreInv(BaseConstant.IS_YESNO_YES);
//		}else if(isPreInv.equals(String.valueOf(BaseConstant.IS_YESNO_NO))){
//			qc.setIsPreInv(BaseConstant.IS_YESNO_NO);
//		}else{
//			qc.setIsPreInv(BaseConstant.IS_YESNO_NO);
//		}
//
//		if(StringUtils.isNotEmpty(extPaySchMId)){
//			qc.setPaySchMId(Long.valueOf(extPaySchMId));
//		}
//		if(StringUtils.isNotEmpty(extPrjId)){
//			List<Long> prjIdList = new ArrayList<>();
//			prjIdList.add(Long.valueOf(extPrjId));
//			qc.setPrjIdList(prjIdList);
//		}
//
//		List<String> feeTypCdList = new ArrayList<>();
//		feeTypCdList.add(DictionaryConstant.CODE_PRJ_QUAT_FEE_TYP_CD_S02);
//		feeTypCdList.add(DictionaryConstant.CODE_PRJ_QUAT_FEE_TYP_CD_S03);
//		qc.setFeeTypCdList(feeTypCdList);
//		qc.setBillStsCd(DictionaryConstant.CODE_PRJ_BILL_STS_CD_2);
//		//组织架构代码
//		qc.setOrgCd(CurrentThreadContext.getCurrentOrgCd());
//		//系统代码
//		qc.setSysCd(CurrentThreadContext.getFlServiceSysCd());
//
//		List<String> audStsCdList = new ArrayList<>();
//		audStsCdList.add(FlowConstant.FLOW_CHECK_STATE_PASS);
//		audStsCdList.add(FlowConstant.FLOW_CHECK_STATE_NO_PASS);
//		qc.setAudStsCdList(audStsCdList);
//		qc.setIsDel(CustomerConstant.CST_IS_DEL_2);//删除值为2的说明是财务作废的项可以后面继续开票
//		page.setCondition(qc);
//		List<PrjBillApplyRecVO> list = null;
//		try {
//			list = this.prjBillApplyService.searchApplyList(qc);
//		} catch (BaseException e) {
//			BaseLogUtils.info(logger, "initApplyList", "查询数据完成-业务异常.", CurrentThreadContext.getCurrentUserName(), e);
//		} catch (Exception e) {
//			BaseLogUtils.error(logger, "initApplyList", "查询数据完成-业务异常.", CurrentThreadContext.getCurrentUserName(), e);
//		}
//
//		ListPageVO<PrjBillApplyRecVO> listPage = new ListPageVO<PrjBillApplyRecVO>(list, 0);
//		BaseLogUtils.info(logger, "initApplyList", "查询数据完成. DATA:" + JSONObject.toJSONString(page), CurrentThreadContext.getCurrentUserName());
//		return listPage;
//	}

    /**
     * 初始化支付表申请列表
     */
	@RequestMapping(value = "/initApplyList.do", method = { RequestMethod.GET})
	@ResponseBody
	public Object initApplyList(HttpServletRequest request, HttpServletResponse response) {
		String cntNo = request.getParameter("cntNo");
		String prjId = request.getParameter("prjId");
		String cstId = request.getParameter("cstId");
        String billWayCd = request.getParameter("billWayCd");
        String paySchId = request.getParameter("paySchId");
        List<ValidInvoiceDataDTO> list = null;
		try {
            SearchValidInvoiceQueryCondition condition = new SearchValidInvoiceQueryCondition();
			condition.setPrjId(Long.parseLong(prjId));
			condition.setLsCntNo(cntNo);
            condition.setCstId(Long.valueOf(cstId));
            condition.setBillWayCd(billWayCd);
            if (StringUtils.isNotEmpty(paySchId)) {
                condition.setPaySchId(Long.valueOf(paySchId));
            }
            // condition.setLimitDate();
			list = this.prjBillApplyService.searchValidInvoiceList(condition);
            if (CollectionUtils.isNotEmpty(list)) {
                List<ValidInvoiceDataDTO> data = new ArrayList<>();
                if (PrjBillApplyConstant.BILL_WAY_CD_1.equals(billWayCd)) {
                    // 拿到电子发票税率不为空的数据
                    list.stream().forEach(entity -> {
                        if (null != entity.getTaxRate()) {
                            data.add(entity);
                        }
                    });
                } else if (PrjBillApplyConstant.BILL_WAY_CD_2.equals(billWayCd)) {
                    // 拿到纸质发票
                    list.stream().forEach(entity -> {
                        if (null != entity.getTaxRate() || PrjBillApplyConstant.BILL_TYP_CD_4.equals(entity.getBillTypCd())) {
                            data.add(entity);
                        }
                    });
                }
                ListPageVO<ValidInvoiceDataDTO> listPage = new ListPageVO<ValidInvoiceDataDTO>(data, data.size());
                return listPage;
            }
            ListPageVO<ValidInvoiceDataDTO> listPage = new ListPageVO<ValidInvoiceDataDTO>(list, 0);
            return listPage;
		} catch (BaseException e) {
		    BaseLogUtils.newLogger("初始化支付表申请列表异常").setKeys("prjId:" + prjId, "cstId:" + cstId).setThrowable(e).error(LogExceptionEnum.COMMON_CODE_0002);
		    throw e;
		} catch (Exception e) {
            BaseLogUtils.newLogger("初始化支付表申请列表异常").setKeys("prjId:" + prjId, "cstId:" + cstId).setThrowable(e).error(LogExceptionEnum.COMMON_CODE_0002);
            throw e;
		}

	}
	
	/**
	 * 获取请求参数
	 * @param request
	 * @return 返回需要处理的对象
	 */
	private PrjBillApplyVO getRequestParms(HttpServletRequest request) throws BaseException{
		String cstId = request.getParameter("cstId");//客户ID
		String cstNm = request.getParameter("cstNm");//客户名称
		String orgNm = request.getParameter("orgNm");//组织架构名称
		String rcverNm = request.getParameter("rcverNm");//收件人
		String rcverTel = request.getParameter("rcverTel");//收件人联系电话
		String rcvAddr = request.getParameter("rcvAddr");//收货地址
		String grid = request.getParameter("grid");//支付表列表
		String applyRem = request.getParameter("applyRem");//备注
		
		String isPreInv = request.getParameter("isPreInv");//是否提前开票
		String invTel = request.getParameter("invTel");//被开票电话
		String invAccNo = request.getParameter("invAccNo");//被开票账户
		String invTaxId = request.getParameter("invTaxId");//纳税人识别号
		String invTitle = request.getParameter("invTitle");//发票抬头
		String invAddr = request.getParameter("invAddr");//开票地址
		String invBkCd = request.getParameter("invBkCd");//被开票人开户行
		
		
		String rlFlowCd = request.getParameter("rlFlowCd");//默认为正常申请开票流程
		
		if(StringUtils.isEmpty(rlFlowCd)){//如果为空则为正常开票流程
			rlFlowCd = PropertiesCacheUtils.getProperty(fl.constant.facade.framework.constant.DictionaryConstant.CODE_PRJ_BILL_APPLY_RL_FLOW_CD_A);
		}
		if(StringUtils.isEmpty(cstId)){
			throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_602, "客户ID不能为空!");
		}
		
		if(StringUtils.isEmpty(cstNm)){
			throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_602, "客户名字不能为空!");
		}
		
		if(StringUtils.isEmpty(orgNm)){
			throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_602, "组织架构名称不能为空!");
		}
		
		if(StringUtils.isEmpty(rcverNm)){
			throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_602, "收件人不能为空!");
		}
		
		if(StringUtils.isEmpty(rcverTel) || !StringUtils.isMobilePhoneAndFixedPhone(rcverTel)){
			throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_602, "请录入正确的收件人联系电话!如:13888888888 或 010-88888888");
		}
		
		if(StringUtils.isEmpty(rcvAddr)){
			throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_602, "收获地址不能为空!");
		}
		
		if(StringUtils.isEmpty(isPreInv)){
			throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_602, "请选择是否提前开票选项!");
		}
		
		if(StringUtils.isEmpty(grid)){
			throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_602, "请选择开票数据!");
		}
		
		PrjBillApplyVO entity = new PrjBillApplyVO();
		entity.setApplyRem(applyRem);
		entity.setApplyTm(new Date());
		entity.setAudStsCd(FlowConstant.FLOW_CHECK_STATE_NON);//未审核
		entity.setBuOrgCd(CurrentThreadContext.getCurrentBuOrgCd());
		entity.setCrtTm(new Date());
		entity.setCrtUsrId(CurrentThreadContext.getCurrentUserId());
		entity.setCstMgrId(CurrentThreadContext.getCurrentUserId());
		entity.setCstMgrNm(CurrentThreadContext.getCurrentUserName());
		entity.setCstMgrOrgCd(CurrentThreadContext.getCurrentOrgCd());
		entity.setCstNm(cstNm);
		entity.setCstId(Long.valueOf(cstId));
		entity.setIsDel(BaseConstant.IS_YESNO_NO);
		entity.setRcvAddr(rcvAddr);
		entity.setRcverNm(rcverNm);
		entity.setRcverTel(rcverTel);
		entity.setIsPreInv(Integer.valueOf(isPreInv));
		entity.setInvTitle(invTitle);
		entity.setInvTaxId(invTaxId);
		entity.setInvTel(invTel);
		entity.setInvAccNo(invAccNo);
		entity.setInvAddr(invAddr);
		entity.setInvBkCd(invBkCd);
		entity.setRlFlowCd(rlFlowCd);
		entity.setBillWayCd(PrjBillApplyConstant.BILL_WAY_CD_2);
		
		//解析GRID中支付表数据
		JSONArray array = JSONArray.fromObject(grid);
		if(null == array || !array.isArray()){
			throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_602, "开票数据解析失败!");
		}
		
		String billTypCdA = PropertiesCacheUtils.getProperty(fl.constant.facade.framework.constant.DictionaryConstant.CODE_BILL_TYP_CD_A);
		String billTypCdB = PropertiesCacheUtils.getProperty(fl.constant.facade.framework.constant.DictionaryConstant.CODE_BILL_TYP_CD_B);
		Boolean hasHighVal = false;//是否有增值税发票
		
		List<PrjBillFeeRVO> prjBillFeeRVOList = new ArrayList<>();
		
		net.sf.json.JSONObject obj = null;
		PrjBillFeeRVO prjBillFeeRVO = null;
		List<Long> payDtlIds = new ArrayList<>();
		for (Object object : array) {
			obj = (net.sf.json.JSONObject)object;
			if(null == obj) continue;
			prjBillFeeRVO = new PrjBillFeeRVO();
			String billTypCd = obj.optString("billTypCd","");
			String feeTypCd = obj.optString("feeTypCd","");
			Long paySchId = obj.optLong("paySchId",0L);
			Long paySchDtlId = obj.optLong("payDetailId",0L);
            if (0L != paySchDtlId) {
                payDtlIds.add(paySchDtlId);
            }
			String paySchNo = obj.optString("paySchNo","");
			Long odId = obj.optLong("odId",0L);
			Integer payPd = obj.optInt("payPd", 0);
            String lsCntNo = obj.optString("lsCntNo", "");
			Long paidUpAmt = obj.optLong("vfAmt", 0L);
            Long feeAmt = obj.optLong("feeAmt", 0L);
			String capFlow = obj.optString("capFlow","");//资金流向
            Double taxRate = obj.optDouble("taxRate",0d);//资金流向
            Long taxAmt = obj.optLong("taxAmt",0L);//资金流向
			prjBillFeeRVO.setBillTypCd(billTypCd);
			prjBillFeeRVO.setFeeTypCd(feeTypCd);
			prjBillFeeRVO.setPaySchDtlId(paySchDtlId);
			prjBillFeeRVO.setPaySchId(paySchId);
			prjBillFeeRVO.setPaySchNo(paySchNo);
			prjBillFeeRVO.setOdId(odId);
			prjBillFeeRVO.setIsDel(BaseConstant.IS_YESNO_NO);
			prjBillFeeRVO.setPayPd(payPd);
			prjBillFeeRVO.setBillAmt(paidUpAmt);
            prjBillFeeRVO.setFeeAmt(feeAmt);
			prjBillFeeRVO.setCapFlow(capFlow);
            prjBillFeeRVO.setLsCntNo(lsCntNo);
            prjBillFeeRVO.setTaxRate(taxRate);
            prjBillFeeRVO.setTaxAmt(taxAmt);
			prjBillFeeRVOList.add(prjBillFeeRVO);
			//判断是否有增值税发票
			if(billTypCd.equals(billTypCdA) || billTypCd.equals(billTypCdB)){
				hasHighVal = true;
			}
		}
		this.prjBillApplyService.checkInvoiceFeeIfPresent(payDtlIds);
		/**
		 * 1、费用项里面有一项是增值税发票类型的则必须要填写抬头等所有信息。
		 * 2、抬头与客户名称不一样要上传附件，提前开票也是要上传附件。
		 */
		if(hasHighVal){//有增值税发票则判断所有填写项
			if(StringUtils.isEmpty(invTel) || !StringUtils.isMobilePhoneAndFixedPhone(invTel)){
				throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_602, "请录入正确的开票人电话!如:13888888888 或 010-88888888 !");
			}
			
			if(StringUtils.isEmpty(invTaxId)){
				throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_602, "请录入纳税人识别号!");
			}
			
			if(StringUtils.isEmpty(invTitle)){
				throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_602, "请录入发票抬头!");
			}

		}
		
		//检查附件是否需要上传
		if(BaseConstant.IS_YESNO_YES == entity.getIsPreInv().intValue() 
				|| !entity.getCstNm().equals(invTitle)){
			String attchmnt = request.getParameter("docArray");
			if(StringUtils.isEmpty(attchmnt)){
				throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_602, "请上传附件!");
			}
			
			JSONArray attchmntArray = JSONArray.fromObject(attchmnt);
			if(null == attchmntArray || attchmntArray.isEmpty() || !attchmntArray.isArray()){//处理附件
				throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_602, "请上传附件!");
			}
		}
		entity.setPrjBillFeeRVOList(prjBillFeeRVOList);
		return entity;
	}

    /**
     * 修改票据申请信息
     */
    @RequestMapping(value = "/modifyApplyInfo.do", method = { RequestMethod.POST })
    @ResponseBody
    public Object modifyApplyInfo(HttpServletRequest request, HttpServletResponse response) throws BaseException {
        String rcverNm = request.getParameter("rcverNm");
        String rcverTel = request.getParameter("rcverTel");
        String rcvAddr = request.getParameter("rcvAddr");
        String expCorp = request.getParameter("expCorp");
        String trcNo = request.getParameter("trcNo");
        String applyId = request.getParameter("applyId");
        DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, SysLogConstant.LOG_CMM_UPDATE_SUCC);
        PrjBillApplyVO entity = null;
        try {
            if(StringUtils.isEmpty(applyId)){
                throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_600, "申请单ID不能为空!");
            }
            if(StringUtils.isEmpty(rcverNm)){
                throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_600, "收件人不能为空!");
            }
            if(StringUtils.isEmpty(rcverTel)){
                throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_600, "联系电话不能为空!");
            }
            if(StringUtils.isEmpty(rcvAddr)){
                throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_600, "收件地址不能为空!");
            }
            if(StringUtils.isEmpty(expCorp)){
                throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_600, "快递公司不能为空!");
            }
            if(StringUtils.isEmpty(trcNo)){
                throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_600, "快递单号不能为空!");
            }
            //组装数据
            entity = new PrjBillApplyVO();
            entity.setId(Long.valueOf(applyId));
            entity.setRcvAddr(rcvAddr);
            entity.setRcverNm(rcverNm);
            entity.setRcverTel(rcverTel);
            entity.setExpCorp(expCorp);
            entity.setTrcNo(trcNo);
            entity.setMdfTm(new Date());
            entity.setMdfUsrId(CurrentThreadContext.getCurrentUserId());
            this.prjBillApplyService.modify(entity);
        }catch (BaseException ex) {
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo(ex.getMessage());
            BaseLogUtils.newLogger("修改发票申请信息失败").setKeys("entity：" + JSONObject.toJSONString(entity)).setThrowable(ex).error(LogExceptionEnum.COMMON_CODE_0002);
        }catch (Exception ex) {
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo(SysLogConstant.LOG_CMM_OPERATE_FAIL);
            BaseLogUtils.newLogger("修改发票申请信息失败").setKeys("entity：" + JSONObject.toJSONString(entity)).setThrowable(ex).error(LogExceptionEnum.COMMON_CODE_0002);
        }
        return result;
    }

	/**
	 * 新增
	 */
	@RequestMapping(value = "/add.do", method = { RequestMethod.POST })
	@ResponseBody
	public Object add(HttpServletRequest request, HttpServletResponse response) throws BaseException {
		DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, SysLogConstant.LOG_CMM_ADD_SUCC);
		PrjBillApplyVO entity = null;
		try {
			entity = this.getRequestParms(request);
			Long id = this.prjBillApplyService.add(entity);
			result.setData(id);
			//上传附件
			uploadAttchment(request, result, id);
			BaseLogUtils.info(logger, "add", "新增数据.[id="+id+"] DATA:" + JSONObject.toJSONString(entity), CurrentThreadContext.getCurrentUserName());
		}catch (BaseException ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(ex.getMessage());
			BaseLogUtils.newLogger("新增发票申请数据失败").setKeys("entity:" + JSON.toJSONString(entity)).setThrowable(ex).error(LogExceptionEnum.COMMON_CODE_0002);
		}catch (Exception ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(SysLogConstant.LOG_CMM_SYS_ERROR);
            BaseLogUtils.newLogger("新增发票申请数据失败").setKeys("entity:" + JSON.toJSONString(entity)).setThrowable(ex).error(LogExceptionEnum.COMMON_CODE_0002);
		}

		return result;
	}
	
	/**
	 * 新增
	 */
	@RequestMapping(value = "/addClearPay.do", method = { RequestMethod.POST })
	@ResponseBody
	public Object addClearPay(HttpServletRequest request, HttpServletResponse response) throws BaseException {
		DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, SysLogConstant.LOG_CMM_ADD_SUCC);
		PrjBillApplyVO entity = null;
		try {
			entity = this.getRequestParms(request);
			String procInstId = request.getParameter("procInstId");//流程实例ID
			String extPaySchMId = request.getParameter("extPaySchMId"); 
			
			if(StringUtils.isEmpty(procInstId)){
				throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_602, "流程实例ID不能为空!");
			}
			
			if(StringUtils.isEmpty(extPaySchMId)){
				throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_602, "支付表主键不能为空!");
			}
			entity.setPInstId(procInstId);//流程实例ID在后面要把结清的流程数据中部分数据新增到开票流程中
			entity.setpInstBusKey(Long.valueOf(extPaySchMId));
			String rlFlowCd = PropertiesCacheUtils.getProperty(fl.constant.facade.framework.constant.DictionaryConstant.CODE_PRJ_BILL_APPLY_RL_FLOW_CD_B);
			entity.setRlFlowCd(rlFlowCd);
			Long id = this.prjBillApplyService.addClearPay(entity);
			result.setData(id);
			//上传附件
			uploadAttchment(request, result, id);
			BaseLogUtils.info(logger, "addClearPay", "新增数据.[id="+id+"] DATA:" + JSONObject.toJSONString(entity), CurrentThreadContext.getCurrentUserName());
		}catch (BaseException ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(ex.getMessage());
			BaseLogUtils.info(logger, "addClearPay", "新增数据失败.DATA:" + JSONObject.toJSONString(entity) + ex.getMessage(), CurrentThreadContext.getCurrentUserName());
		}catch (Exception ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(SysLogConstant.LOG_CMM_SYS_ERROR);
			BaseLogUtils.error(logger, "addClearPay", "新增数据失败.DATA:" + JSONObject.toJSONString(entity) + ex.getMessage(), CurrentThreadContext.getCurrentUserName());
		}

		return result;
	}

	/**
	 * 修改
	 */
	@RequestMapping(value = "/modify.do", method = { RequestMethod.POST })
	@ResponseBody
	public Object modify(HttpServletRequest request, HttpServletResponse response) throws BaseException {
		String id = request.getParameter("applyId");
		String rcverNm = request.getParameter("rcverNm");//收件人
		String rcverTel = request.getParameter("rcverTel");//收件人联系电话
		String rcvAddr = request.getParameter("rcvAddr");//收货地址
		String grid = request.getParameter("grid");//支付表列表
		String applyRem = request.getParameter("applyRem");//备注
		
		//String isPreInv = request.getParameter("isPreInv");//是否提前开票
		String invTel = request.getParameter("invTel");//被开票电话
		String invAccNo = request.getParameter("invAccNo");//被开票账户
		String invTaxId = request.getParameter("invTaxId");//纳税人识别号
		String invTitle = request.getParameter("invTitle");//发票抬头
		String invAddr = request.getParameter("invAddr");//开票地址
		String invBkCd = request.getParameter("invBkCd");//被开票人开户行
		
		String rlFlowCd = request.getParameter("rlFlowCd");//默认为正常申请开票流程
		if(StringUtils.isEmpty(rlFlowCd)){//如果为空则为正常开票流程
			rlFlowCd = PropertiesCacheUtils.getProperty(fl.constant.facade.framework.constant.DictionaryConstant.CODE_PRJ_BILL_APPLY_RL_FLOW_CD_A);
		}
		DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, SysLogConstant.LOG_CMM_UPDATE_SUCC);
		if(StringUtils.isEmpty(id)){
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(SysLogConstant.LOG_CMM_DATA_PK_IS_EMPTY);
			BaseLogUtils.info(logger, "modify", "修改数据,主键不存在.[id="+id+"]", CurrentThreadContext.getCurrentUserName());
			return result;
		}
		PrjBillApplyVO entity = null;
		try {
			
			if(StringUtils.isEmpty(rcverNm)){
				throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_602, "收件人不能为空!");
			}
			
			if(StringUtils.isEmpty(rcverTel) || !StringUtils.isMobilePhoneAndFixedPhone(rcverTel)){
				throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_602, "请录入正确的收件人联系电话!如:13888888888 或 010-88888888");
			}
			
			if(StringUtils.isEmpty(rcvAddr)){
				throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_602, "收获地址不能为空!");
			}
			
			/*if(StringUtils.isEmpty(isPreInv)){
				throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_602, "请选择是否提前开票选项!");
			}*/
			
			if(StringUtils.isEmpty(grid)){
				throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_602, "请选择开票数据!");
			}
			
			entity = new PrjBillApplyVO();
			entity.setId(Long.valueOf(id));
			entity.setRcvAddr(rcvAddr);
			entity.setRcverTel(rcverTel);
			entity.setRcverNm(rcverNm);
			if(StringUtils.isNotEmpty(applyRem)){
				entity.setApplyRem(applyRem);
			}
			//entity.setIsPreInv(Integer.parseInt(isPreInv));
			entity.setInvTitle(invTitle);
			entity.setInvTaxId(invTaxId);
			entity.setInvTel(invTel);
			entity.setInvAccNo(invAccNo);
			entity.setInvAddr(invAddr);
			entity.setInvBkCd(invBkCd);
			entity.setRlFlowCd(rlFlowCd);
			
			//解析GRID中支付表数据
			JSONArray array = JSONArray.fromObject(grid);
			if(null != array && array.isArray()){
				List<PrjBillFeeRVO> prjBillFeeRVOList = new ArrayList<>();
				net.sf.json.JSONObject obj = null;
				PrjBillFeeRVO prjBillFeeRVO = null;
				for (Object object : array) {
					obj = (net.sf.json.JSONObject)object;
					if(null == obj) continue;
					prjBillFeeRVO = new PrjBillFeeRVO();
					Long rid = obj.optLong("rId", 0L);
					String billTypCd = obj.optString("billTypCd","");
					prjBillFeeRVO.setId(rid);
					prjBillFeeRVO.setBillTypCd(billTypCd);
					prjBillFeeRVOList.add(prjBillFeeRVO);
				}
				entity.setPrjBillFeeRVOList(prjBillFeeRVOList);
			}
			
			boolean success = this.prjBillApplyService.modify(entity);
			if(!success){
				result.setSuccess(BaseConstant.IS_YESNO_NO);
				result.setInfo(SysLogConstant.LOG_CMM_SYS_ERROR);
				BaseLogUtils.info(logger, "modify", "修改失败.[id="+id+"] DATA:" + JSONObject.toJSONString(entity), CurrentThreadContext.getCurrentUserName());
			}
			//处理附件
			this.uploadAttchment(request, result, entity.getId());
			BaseLogUtils.info(logger, "modify", "修改成功.[id="+id+"] DATA:" + JSONObject.toJSONString(entity), CurrentThreadContext.getCurrentUserName());
		}catch (BaseException ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(ex.getMessage());
			BaseLogUtils.info(logger, "modify", "修改失败.[id="+id+"] DATA:" + JSONObject.toJSONString(entity) + ex.getMessage(), CurrentThreadContext.getCurrentUserName());
		}catch (Exception ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(SysLogConstant.LOG_CMM_SYS_ERROR);
			BaseLogUtils.error(logger, "modify", "修改失败.[id="+id+"] DATA:" + JSONObject.toJSONString(entity) + ex.getMessage(), CurrentThreadContext.getCurrentUserName());
		}
		return result;
	}
	
	/**
	 * 得到一条记录
	 * 
	 * @param request
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value = "/getById.do", method = { RequestMethod.GET})
	@ResponseBody
	public Object getById(HttpServletRequest request, HttpServletResponse response) throws BaseException {
		String id = request.getParameter("id");
		DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, SysLogConstant.LOG_CMM_OPERATE_SUCC);
		if(StringUtils.isEmpty(id)){
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(SysLogConstant.LOG_CMM_DATA_PK_IS_EMPTY);
			BaseLogUtils.info(logger, "getById", "获取数据,主键不存在.[id="+id+"]", CurrentThreadContext.getCurrentUserName());
			return result;
		}
		
		try {
			PrjBillApplyVO vo = this.prjBillApplyService.selectById(Long.valueOf(id));
			if(null == vo){
				result.setSuccess(BaseConstant.IS_YESNO_NO);
				result.setInfo(SysLogConstant.LOG_CMM_QUERY_DATA_IS_EMPTY);
				BaseLogUtils.info(logger, "getById", "获取数据,数据不存在.[id="+id+"]", CurrentThreadContext.getCurrentUserName());
			}
            if (StringUtils.isNotEmpty(vo.getCstId())) {
                CstBscInfoVO cstBscInfoVO = this.cstBscInfoService.selectById(vo.getCstId());
                if (null != cstBscInfoVO) {
                    List<KeyValueVO> kvList = this.sysDictionaryService.getKvList(DictionaryConstant.CODE_GRP_CST_TYP_CD, CurrentThreadContext.getCurrentSysCd(), "0000");
                    for (KeyValueVO keyValueVO : kvList) {
                        if (keyValueVO.getKey().equals(cstBscInfoVO.getCstTypCd())) {
                            vo.setCstTypNm(keyValueVO.getValue());
                            break;
                        }
                    }
                }
            }

            SysUsrVO sysUsrVO = this.sysUsrService.selectById(vo.getCrtUsrId(), CurrentThreadContext.getCurrentSysCd());
            if (null != sysUsrVO) {
                vo.setApplyNm(sysUsrVO.getRefRlNm());
            }
            //获取流程发起人信息
			getSysUsrInfo(id,vo);
			//设置默认快递公司
			if(StringUtils.isEmpty(vo.getExpCorp())){
				vo.setExpCorp("顺丰快递");
			}
			result.setData(vo);
			BaseLogUtils.info(logger, "getById", "获取数据.[id="+id+"]", CurrentThreadContext.getCurrentUserName());
		}catch(BaseException ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(ex.getMessage());
			BaseLogUtils.info(logger, "getById", "获取失败.[id="+id+"]"+ex.getMessage(), CurrentThreadContext.getCurrentUserName());
		}catch(Exception ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(SysLogConstant.LOG_CMM_SYS_ERROR);
			BaseLogUtils.error(logger, "getById", "获取失败.[id="+id+"]"+ex.getMessage(), CurrentThreadContext.getCurrentUserName());
		}
		return result;
	}
	
	private void getSysUsrInfo(String id, PrjBillApplyVO vo) {
		try{
			// 查询创建者信息
			if(StringUtils.isNotEmpty(id)){
				SysFlowSHQueryCondition condition = new SysFlowSHQueryCondition();
				condition.setDataId(Long.valueOf(id));
				condition.setStatus(1);
				condition.setWordsInTheTable("CST");
				condition.setSysCd(CurrentThreadContext.getFlServiceSysCd());
				List<SysFlowSHDTO> flowList = flowQueryApiService.searchFlowSHList(condition);
				if(CollectionUtils.isNotEmpty(flowList)){
					Long crtUsrId = flowList.get(0).getCrtUsrId();
					if(StringUtils.isNotEmpty(crtUsrId)){
						//查询系统用户信息
						List<Long> usrIds = new ArrayList<>();
						usrIds.add(crtUsrId);
						SysUsrQueryCondition qc = new SysUsrQueryCondition();
						qc.setSysCd(CurrentThreadContext.getFlServiceSysCd());
						qc.setUsrIds(usrIds);
						List<SysUsrDTO> usrList = sysUsrService.searchSysUsrList(qc);
						if(CollectionUtils.isNotEmpty(usrList)){
							SysUsrDTO sysUsrDTO = usrList.get(0);
							vo.setSysUsrMp(sysUsrDTO.getMp());
							vo.setSysUsrRlNm(sysUsrDTO.getRefRlNm());
						}
					}
				}
			}
		}catch(Exception e){
			BaseLogUtils.error(logger, "getSysUsrInfo", "获取失败.[id="+id+"]", CurrentThreadContext.getCurrentUserName(),e);
		}
	}

    /**
     * 开纸质发票
     */
    @RequestMapping(value = "/applyInvoice.do", method = { RequestMethod.POST })
    @ResponseBody
    public Object applyInvoice(HttpServletRequest request, HttpServletResponse response) throws BaseException {
        String applyId = request.getParameter("applyId");
        String billTypCd = request.getParameter("billTypCd");
        String billNo = request.getParameter("billNo");
        // 费用项集合
        String paySchFeeList = request.getParameter("paySchFeeList");
        // 收件人
        String rcverNm = request.getParameter("rcverNm");
        // 收件地址
        String rcvAddr = request.getParameter("rcvAddr");
        // 联系电话
        String rcverTel = request.getParameter("rcverTel");
        // 快递公司
        String expCorp = request.getParameter("expCorp");
        // 快递单号
        String trcNo = request.getParameter("trcNo");
        DataResultDTO resultDTO = new DataResultDTO(BaseConstant.IS_YESNO_YES, SysLogConstant.LOG_CMM_OPERATE_SUCC);
        try {
            if (StringUtils.isEmpty(paySchFeeList)) {
                throw new BaseException("请选择需要开票的费用项数据！");
            }
            List<PrjBillFeeRDTO> paperInvoiceList = JSON.parseArray(paySchFeeList, PrjBillFeeRDTO.class);
            if (StringUtils.isEmpty(applyId)) {
                throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_600, "申请单ID不能为空!");
            }
            if (StringUtils.isEmpty(billTypCd)) {
                throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_600, "开票类型不能为空!");
            }
            InvoiceApplyReqDTO reqDTO = new InvoiceApplyReqDTO();
            if (StringUtils.isNotEmpty(billNo)) {
                reqDTO.setBillNo(billNo);
            }
            // 纸质开具
            reqDTO.setId(Long.valueOf(applyId));
            reqDTO.setBillTypCd(billTypCd);
            reqDTO.setCrtUsrId(CurrentThreadContext.getCurrentUserId());
            reqDTO.setPaperInvoiceList(paperInvoiceList);
            paperInvoiceList.stream().forEach(paperInvoice -> {
                reqDTO.setLsCntNo(paperInvoice.getLsCntNo());
                return;
            });
            reqDTO.setRcverNm(rcverNm);
            reqDTO.setRcvAddr(rcvAddr);
            reqDTO.setRcverTel(rcverTel);
            reqDTO.setExpCorp(expCorp);
            reqDTO.setTrcNo(trcNo);
            resultDTO = this.prjBillApplyService.executeDoInvoicePaper(reqDTO);
        } catch (BaseException ex) {
            BaseLogUtils.newLogger("开具纸质发票异常").setKeys("applyId:" + applyId).setThrowable(ex).error(LogExceptionEnum.COMMON_CODE_0002);
            resultDTO.setSuccess(BaseConstant.IS_YESNO_NO);
            resultDTO.setInfo(ex.getMessage());
        } catch (Exception ex) {
            BaseLogUtils.newLogger("开具纸质发票异常").setKeys("applyId:" + applyId).setThrowable(ex).error(LogExceptionEnum.COMMON_CODE_0002);
            resultDTO.setSuccess(BaseConstant.IS_YESNO_NO);
            resultDTO.setInfo(ex.getMessage());
        }
        return resultDTO;
    }
	
	/**
	 * 作废
	 */
	@RequestMapping(value = "/stopUsedZF.do", method = { RequestMethod.POST })
	@ResponseBody
	public Object stopUsedZF(HttpServletRequest request, HttpServletResponse response) throws BaseException {
		String id = request.getParameter("id");
		DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, SysLogConstant.LOG_CMM_OPERATE_SUCC);
		if(StringUtils.isEmpty(id)){
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(SysLogConstant.LOG_CMM_DATA_PK_IS_EMPTY);
			BaseLogUtils.info(logger, "stopUsedZF", "作废开票申请数据,主键不存在.[id="+id+"]", CurrentThreadContext.getCurrentUserName());
			return result;
		}
		try {
			boolean success = this.prjBillApplyService.modifyStopUsedZF(Long.valueOf(id), DictionaryConstant.CODE_PRJ_BILL_STS_CD_2);
			if(!success){
				result.setSuccess(BaseConstant.IS_YESNO_NO);
				result.setInfo(SysLogConstant.LOG_CMM_OPERATE_FAIL);
				BaseLogUtils.info(logger, "stopUsedZF", "操作失败.[id="+id+"]", CurrentThreadContext.getCurrentUserName());
			}
			BaseLogUtils.info(logger, "stopUsedZF", "操作成功.[id="+id+"]", CurrentThreadContext.getCurrentUserName());
		}catch (BaseException ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(ex.getMessage());
			BaseLogUtils.info(logger, "stopUsedZF", "操作失败.[id="+id+"]"+ ex.getMessage(), CurrentThreadContext.getCurrentUserName());
		}catch (Exception ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(SysLogConstant.LOG_CMM_SYS_ERROR);
			BaseLogUtils.error(logger, "stopUsedZF", "操作失败.[id="+id+"]" + ex.getMessage(), CurrentThreadContext.getCurrentUserName());
		}
		return result;
	}
	
	/**
	 * 启动流程
	 */
	@RequestMapping(value = "/addFlowStart.do", method = { RequestMethod.POST})
	@ResponseBody
	public Object addFlowStart(HttpServletRequest request, HttpServletResponse response) {
		String procDefKey = request.getParameter("procDefKey");
		String procDefId = request.getParameter("procDefId");
		String procNo = request.getParameter("procNo");
		String cstId = request.getParameter("cstId");
		String cstNm = request.getParameter("cstNm");
		
		DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, SysLogConstant.LOG_CMM_OPERATE_SUCC);
		if(StringUtils.isEmpty(procDefKey)){
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo("流程定义KEY不能为空!");
			return result;
		}
		
		if(StringUtils.isEmpty(procDefId)){
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo("流程定义ID不能为空!");
			return result;
		}

		if(StringUtils.isEmpty(procNo)){
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo("流程编号不能为空!");
			return result;
		}
		FlowStartParamsDTO flowStartParamsDTO = new FlowStartParamsDTO();
		PrjBillApplyVO entity = null;
		try {
			//先把数据保存后返回主键在提交
			entity = this.getRequestParms(request);
			//流程定义Key和流程定义ID 如果是前端选择的则直接指定,如果不是则系统自动按照配置选择唯一一条记录,如果找不到会提示
			flowStartParamsDTO.setProcDefKey(procDefKey);
			flowStartParamsDTO.setProcDefId(procDefId);
			flowStartParamsDTO.setProcNo(procNo);
			flowStartParamsDTO.setCrtUsrId(CurrentThreadContext.getCurrentUserId());
			//flowStartParamsDTO.setBusinessKey(String.valueOf(id));
			flowStartParamsDTO.setOrgCd(CurrentThreadContext.getCurrentOrgCd());
			flowStartParamsDTO.setSysCd(CurrentThreadContext.getCurrentSysCd());
			flowStartParamsDTO.setBuOrgCd(CurrentThreadContext.getCurrentBuOrgCd());
			flowStartParamsDTO.setInitiator(String.valueOf(CurrentThreadContext.getCurrentUserId()));
			flowStartParamsDTO.setInitiatorNm(CurrentThreadContext.getCurrentUserName());
			flowStartParamsDTO.setProcPriority(FlowConstant.FLOW_PRIORITY_EMERGENCY);//优先级,可以在界面定义
			flowStartParamsDTO.setBusinessType(FlowConstant.FLOW_BUSINESS_TYP_INVOICE);//TODO 确认用不用
			flowStartParamsDTO.setModelTyp(FlowConstant.FLOW_MODEL_TYP_INVOICE);//需要和流程配置中的模块类型匹配
			flowStartParamsDTO.setSearchDesc(CurrentThreadContext.getCurrentOrgDispNm()+"、承租人、项目名称、查询大字段名称");
			flowStartParamsDTO.setAudStsCd(FlowConstant.FLOW_CHECK_STATE_IN);//审核中
			flowStartParamsDTO.setWordsInTheTable(CustomerConstant.CST_FLOW_S_H_CST);
			flowStartParamsDTO.setCstId(cstId);
			flowStartParamsDTO.setCstNm(cstNm);
			//flowStartParamsDTO.setOrgShtNm(CurrentThreadContext.getCurrentOrgShtNm());
			DataResultDTO dataResultDTO = this.prjBillApplyService.addFlowStart(flowStartParamsDTO, entity);
			if(!dataResultDTO.getCode().equals(BaseExceptionConstant.BASE_EXCEPTION_CODE_200)){
				result.setSuccess(BaseConstant.IS_YESNO_NO);
				result.setInfo(SysLogConstant.LOG_CMM_OPERATE_FAIL);
			}else{
				//如果成功则要加入附件
				this.uploadAttchment(request, result, dataResultDTO.getId());
			}
			flow.business.facade.flow.dto.FlowStartedDTO flowStartedDTO = (flow.business.facade.flow.dto.FlowStartedDTO) dataResultDTO.getData();
			if(StringUtils.isNotEmpty(flowStartedDTO.getMqKey())){
				StringBuffer info = new StringBuffer();
				info.append(result.getInfo());
				info.append(SysLogConstant.LOG_FLOW_NEXT_TASK_OPERATOR);
				result.setData(flowStartedDTO.getMqKey());//表明有值
				result.setInfo(info.toString());
			}
		} catch (BaseException e) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(e.getMessage());
			logger.info(e.getMessage());
		} catch (Exception e) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo("系统错误,请联系管理员！");
			logger.error("系统错误,请联系管理员！"+e.getMessage());
		}
		return result;
	}
	
	/**
	 * 正常根据ID启动流程启动流程
	 */
	@RequestMapping(value = "/addFlowStartNormal.do", method = { RequestMethod.POST})
	@ResponseBody
	public Object addFlowStartNormal(HttpServletRequest request, HttpServletResponse response) {
		String procDefKey = request.getParameter("procDefKey");
		String procDefId = request.getParameter("procDefId");
		String procNo = request.getParameter("procNo");
		String id = request.getParameter("id");
		String cstId = request.getParameter("cstId");
		String cstNm = request.getParameter("cstNm");
		
		DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, SysLogConstant.LOG_CMM_OPERATE_SUCC);
		
		if(StringUtils.isEmpty(procDefKey)){
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo("流程定义KEY不能为空!");
			return result;
		}
		
		if(StringUtils.isEmpty(procDefId)){
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo("流程定义ID不能为空!");
			return result;
		}

		if(StringUtils.isEmpty(procNo)){
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo("流程编号不能为空!");
			return result;
		}
		
		if(StringUtils.isEmpty(id)){
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo("业务主键不能为空!");
			return result;
		}
		
		FlowStartParamsDTO flowStartParamsDTO = new FlowStartParamsDTO();
		try {
			//流程定义Key和流程定义ID 如果是前端选择的则直接指定,如果不是则系统自动按照配置选择唯一一条记录,如果找不到会提示
			flowStartParamsDTO.setAudStsCd(FlowConstant.FLOW_CHECK_STATE_IN);
			flowStartParamsDTO.setWordsInTheTable(CustomerConstant.CST_FLOW_S_H_CST);
			flowStartParamsDTO.setProcDefKey(procDefKey);
			flowStartParamsDTO.setProcDefId(procDefId);
			flowStartParamsDTO.setProcNo(procNo);
			flowStartParamsDTO.setCrtUsrId(CurrentThreadContext.getCurrentUserId());
			flowStartParamsDTO.setBusinessKey(String.valueOf(id));
			flowStartParamsDTO.setOrgCd(CurrentThreadContext.getCurrentOrgCd());
			flowStartParamsDTO.setSysCd(CurrentThreadContext.getCurrentSysCd());
			flowStartParamsDTO.setInitiator(String.valueOf(CurrentThreadContext.getCurrentUserId()));
			flowStartParamsDTO.setInitiatorNm(CurrentThreadContext.getCurrentUserName());
			flowStartParamsDTO.setProcPriority(FlowConstant.FLOW_PRIORITY_EMERGENCY);//优先级,可以在界面定义
			flowStartParamsDTO.setBusinessType(FlowConstant.FLOW_BUSINESS_TYP_INVOICE);//TODO 确认用不用
			flowStartParamsDTO.setModelTyp(FlowConstant.FLOW_MODEL_TYP_INVOICE);//需要和流程配置中的模块类型匹配
			flowStartParamsDTO.setSearchDesc(CurrentThreadContext.getCurrentOrgDispNm()+"、查询大字段名称");
			flowStartParamsDTO.setAudStsCd(FlowConstant.FLOW_CHECK_STATE_IN);//审核中
			flowStartParamsDTO.setWordsInTheTable(CustomerConstant.CST_FLOW_S_H_CST);
			flowStartParamsDTO.setCstId(cstId);
			flowStartParamsDTO.setCstNm(cstNm);
			//flowStartParamsDTO.setOrgShtNm(CurrentThreadContext.getCurrentOrgShtNm());
			DataResultDTO dataResultDTO = this.prjBillApplyService.addFlowStartNormal(flowStartParamsDTO);
			if(!dataResultDTO.getCode().equals(BaseExceptionConstant.BASE_EXCEPTION_CODE_200)){
				result.setSuccess(BaseConstant.IS_YESNO_NO);
				result.setInfo(SysLogConstant.LOG_CMM_OPERATE_FAIL);
			}
			flow.business.facade.flow.dto.FlowStartedDTO flowStartedDTO = (flow.business.facade.flow.dto.FlowStartedDTO) dataResultDTO.getData();
			if(StringUtils.isNotEmpty(flowStartedDTO.getMqKey())){
				StringBuffer info = new StringBuffer();
				info.append(result.getInfo());
				info.append(SysLogConstant.LOG_FLOW_NEXT_TASK_OPERATOR);
				result.setData(flowStartedDTO.getMqKey());//表明有值
				result.setInfo(info.toString());
			}
		} catch (BaseException e) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(e.getMessage());
			logger.info(e.getMessage());
		} catch (Exception e) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo("系统错误,请联系管理员！");
			logger.error("系统错误,请联系管理员！"+e.getMessage());
		}
		return result;
	}
	
	/**
	 * 删除
	 */
	@RequestMapping(value = "/deleteById.do", method = { RequestMethod.POST })
	@ResponseBody
	public Object deleteById(HttpServletRequest request, HttpServletResponse response) throws BaseException {
		String id = request.getParameter("id");
		DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, SysLogConstant.LOG_CMM_DELETE_SUCC);
		if(StringUtils.isEmpty(id) && !StringUtils.isNumeric(id)){
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(SysLogConstant.LOG_CMM_DATA_PK_IS_EMPTY);
			BaseLogUtils.info(logger, "deleteById", "主键不存在.[id="+id+"]", CurrentThreadContext.getCurrentUserName());
			return result;
		}
		try {
			boolean success = this.prjBillApplyService.removeById(Long.valueOf(id));
			if(!success){
				result.setSuccess(BaseConstant.IS_YESNO_NO);
				result.setInfo(SysLogConstant.LOG_CMM_DELETE_FAIL);
				BaseLogUtils.info(logger, "deleteById", "操作失败.[id="+id+"]", CurrentThreadContext.getCurrentUserName());
			}
			BaseLogUtils.info(logger, "deleteById", "操作成功.[id="+id+"]", CurrentThreadContext.getCurrentUserName());
		}catch (BaseException ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(ex.getMessage());
			BaseLogUtils.info(logger, "deleteById", "操作失败.[id="+id+"]"+ ex.getMessage(), CurrentThreadContext.getCurrentUserName());
		}catch (Exception ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(SysLogConstant.LOG_CMM_SYS_ERROR);
			BaseLogUtils.error(logger, "deleteById", "操作失败.[id="+id+"]" + ex.getMessage(), CurrentThreadContext.getCurrentUserName());
		}
		return result;
	}
	
	//上传文件
	private void uploadAttchment(HttpServletRequest request, DataResultVO result, Long id) {
		String attchmnt = request.getParameter("docArray");
		if(StringUtils.isNotEmpty(attchmnt)){
			//上传解析
			try{
				String cfgCd = PropertiesCacheUtils.getProperty(UploadConstant.CFG_PRJ_BILL_APPLY_CD);
				String cfgDtlCd = PropertiesCacheUtils.getProperty(UploadConstant.CFG_DTL_PRJ_BILL_APPLY_CD);
				String tabNm = PropertiesCacheUtils.getProperty(TableConstant.PRJ_BILL_APPLY);
				String cfgOrgCd = PropertiesCacheUtils.getProperty(UploadConstant.CFG_PRJ_BILL_APPLY_ORG_CD);
				Boolean attchmntPass = this.sysUlFilesRecService.addAttchmnt(String.valueOf(id), attchmnt, cfgCd, cfgDtlCd, tabNm, "客户开票申请附件!", null, null, false, cfgOrgCd);
				if(null == attchmntPass || attchmntPass == false){
					result.setInfo(result.getInfo()+"-附件上传失败!");
				}
			}catch(Exception e){
				result.setInfo(result.getInfo()+"-附件上传失败!");
			}
		}
	}

    /**
     * 获取操作发票的报文（1 开具 2 打印 3 作废 4 冲红）
     */
    @RequestMapping(value = "/getInvoiceXml.do", method = { RequestMethod.POST })
    @ResponseBody
    public Object getInvoiceXml(HttpServletRequest request, HttpServletResponse response) throws BaseException {
        String operFlag = request.getParameter("operFlag");
        String bscInfoId = request.getParameter("bscInfoId");
        DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, "纸质发票开具并打印成功");
        try {
            Long bscId = null;
            if (StringUtils.isNotEmpty(bscInfoId)) {
                bscId = Long.valueOf(bscInfoId);
            }
            com.alibaba.fastjson.JSONArray xmls = this.prjBillApplyService.getXml(operFlag, bscId);
            BaseLogUtils.newLogger("获取报文是：").setKeys("operFlag:" + operFlag, "bscInfoId:" + bscInfoId, "xmls:" + JSON.toJSONString(xmls)).info();
            result.setData(xmls);
        } catch (BaseException ex) {
            BaseLogUtils.newLogger("获取发票报文失败").setKeys("operFlag:" + operFlag).setThrowable(ex).error(LogExceptionEnum.COMMON_CODE_0002);
            throw ex;
        } catch (Exception ex) {
            BaseLogUtils.newLogger("获取发票报文失败").setKeys("operFlag:" + operFlag).setThrowable(ex).error(LogExceptionEnum.COMMON_CODE_0002);
            throw ex;
        }
        return result;
    }

    /**
     * 作废纸质发票
     */
    @RequestMapping(value = "/invalidInvoice.do", method = { RequestMethod.POST })
    @ResponseBody
    public Object invalidInvoice(HttpServletRequest request, HttpServletResponse response) throws BaseException {
        String bscInfoId = request.getParameter("bscInfoId");
        DataResultDTO resultDTO = new DataResultDTO(BaseConstant.IS_YESNO_YES, null);
        try {
            PrjBillBscInfoVO prjBillBscInfoVO = new PrjBillBscInfoVO();
            prjBillBscInfoVO.setId(Long.valueOf(bscInfoId));
            prjBillBscInfoVO.setCrtUsrId(CurrentThreadContext.getCurrentUserId());
            prjBillBscInfoVO.setCrtUsrName(CurrentThreadContext.getCurrentUserName());
            resultDTO = this.prjBillApplyService.executeDoInvalidInvoicePaper(PrjBillBscInfoVOTransform.toDTO(prjBillBscInfoVO));
        } catch (BaseException ex) {
            resultDTO.setSuccess(BaseConstant.IS_YESNO_NO);
            resultDTO.setInfo(ex.getMessage());
            BaseLogUtils.newLogger("作废纸质发票失败").setKeys("bscInfoId:" + bscInfoId).setThrowable(ex).error(LogExceptionEnum.COMMON_CODE_0002);
        } catch (Exception ex) {
            resultDTO.setSuccess(BaseConstant.IS_YESNO_NO);
            resultDTO.setInfo(ex.getMessage());
            BaseLogUtils.newLogger("作废纸质发票失败").setKeys("bscInfoId:" + bscInfoId).setThrowable(ex).error(LogExceptionEnum.COMMON_CODE_0002);
        }
        return resultDTO;
    }

}

